package com.ljs.tranctionldemo.service.impl;

import com.ljs.tranctionldemo.bean.Mongo;
import com.ljs.tranctionldemo.bean.Users;
import com.ljs.tranctionldemo.service.MongoService;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: liujinsheng
 * @Date: 2021/6/30.
 */
@Service
public class MongoServiceImpl implements MongoService {
     @Resource
    MongoTemplate mongoTemplate;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add( Mongo mongo){
        mongoTemplate.insert(mongo,"mongo");
        int i=3/0;
        mongo.setId("3");
         mongo.setName("老6");
        mongoTemplate.insert(mongo,"mongo");
    }
}
